﻿#ifndef UTILITY_H
#define UTILITY_H

#include <QByteArray>
#include <QCoreApplication>
#include <QElapsedTimer>
#include <QTime>
#include <QTimer>

#include "math.h"
#include "point.h"

class Utility {
 public:
  static void calcEncoderPosition(double unitLength, double leftInc, double rightInc, double radian, Point* encPose);
  static void calcEncoderPositionAndRad(double unitLength, double base, int leftInc, int rightInc, Point* encPose);
  static void calcCanPosition(double dtime, double dleftSpeed, double drightSpeed, double radian, Point* encPose);
  static void calcCanPositionAndRad(double dtime, double agvRadius, double dleftSpeed, double drightSpeed, Point* encPose);
  static void calcImuEncoderPosition(double unitLength, double leftInc, double rightInc, double radian, Point* encPose);
  static void radianCorrection(double* radian);
  static double calcDistance(const Point& start, const Point& end);
  static double calcRadian(const Point& start, const Point& end);
  static double calcGamma(const Point& cur, const Point& start, const Point& end, bool isForward = true, double r = 400);
  static double calcPointToLineDistance(const Point cur, const Point start, const Point end);
  static double calcRadErrStart2Target(const Point cur, const Point start, const Point end, const bool isforward);
  static Point calcShowPoint(const Point cur, const Point start, const Point end);
  static int ascii2Hex(char input);

  static char BCC(const QByteArray& order, int len);
  static char BCC(const QByteArray& order, int start, int len);
  static uchar CKS(const QByteArray& order, int len);
  static uchar CKS(const QByteArray& order, int start, int len);
  static QByteArray CRC16_ModBus(const QByteArray& order, int num);
  static QByteArray CRC16_X25(const QByteArray& order, int num);
  static QString QbyteArry2Qstring(const QByteArray& data);
  static void blockDelayMs(int ms);
  static void delayMs(const int& mSec);
  static double calcDisShadow2target(const Point& start, const Point& end, const Point& cur);

  static double calcDisPA2LBC(const Point& a, const Point& b, const Point& c);

 private:
  Utility();
};

#endif  // UTILITY_H
